package net.inxweb.bluemeerkat.web.rest.service.glossary;

import java.util.List;

import javax.annotation.Resource;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;

import net.inxweb.bluemeerkat.domain.model.glossary.GlossaryType;
import net.inxweb.bluemeerkat.domain.repository.GlossaryTypeRepository;

import org.jboss.resteasy.annotations.Form;
import org.jboss.resteasy.annotations.providers.jaxb.Wrapped;
import org.jboss.resteasy.spi.WriterException;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;


@Component
@Path("glossary") 
@Transactional
public class GlossaryService { 
	@Resource(name="glossaryTypeRepositoryHibernate")
	private GlossaryTypeRepository glossaryTypeRepository;

	@POST
	@Path("/types") 
	@Produces(MediaType.TEXT_PLAIN) 
	@Transactional(readOnly = false, propagation = Propagation.REQUIRED) 
	public Long createGlossaryType(@Form GlossaryType glossaryType) throws Exception {
		return glossaryTypeRepository.add(glossaryType);
	}
	
 
	@PUT
	@Path("/types/{id}") 		
	@Transactional(readOnly = false, propagation = Propagation.REQUIRED) 
	public void modifyGlossaryType(@PathParam("id") Long id, @Form GlossaryType glossaryType) {
		glossaryType.setId(id); 
		glossaryTypeRepository.modify(glossaryType); 
	}  
	
	@GET
	@Path("/types") 
	@Produces(MediaType.APPLICATION_JSON)
	@Wrapped(element="list")
	public List<GlossaryType> findAllGlossaryType() { 
		return glossaryTypeRepository.findAll(); 
	
	}
	
	@GET
	@Path("/types/{id}") 
	@Produces(MediaType.APPLICATION_JSON) 
	public GlossaryType findGlossaryType(@PathParam("id") Long id) { 
		return glossaryTypeRepository.find(id);

	} 
 	
}
